/**  
 * All rights Reserved, Designed By www.flksh.com
 * @date:   2017-10-30 15:40:52   
 * @Copyright: 2013-2017 www.flksh.com Inc. All rights reserved. 
 * 注意：本内容仅限于上海福乐康社区养老服务有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.zx.cloud.service;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.Period;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zx.cloud.domain.LoanOrder;
import com.zx.cloud.domain.OrderLog;
import com.zx.cloud.domain.OverdueDetail;
import com.zx.cloud.domain.RepayDetail;
import com.zx.cloud.domain.RepayOrder;
import com.zx.cloud.domain.TaskFlag;
import com.zx.cloud.domain.User;
import com.zx.cloud.persistence.CrudMapper;
import com.zx.cloud.persistence.LoanOrderMapper;
import com.zx.cloud.persistence.OrderLogMapper;
import com.zx.cloud.persistence.OverdueDetailMapper;
import com.zx.cloud.persistence.RepayDetailMapper;
import com.zx.cloud.persistence.RepayOrderMapper;
import com.zx.cloud.persistence.TaskFlagMapper;
import com.zx.cloud.persistence.UserMapper;
import com.zx.cloud.util.DateTimeUtil;
import com.zx.cloud.util.OrderNoUtil;
import com.zx.cloud.util.Page;
import com.zx.cloud.util.SmsCodeUtil;

/**
 * 还款订单表
 */
@SpringBootApplication
@Transactional
@Service
public class RepayOrderService extends CrudServiceImpl<RepayOrder> {

	private static final Logger LOGGER = LoggerFactory.getLogger(RepayOrderService.class);
	@Autowired
	private RepayOrderMapper repayOrderMapper;
	
	@Autowired
	private OverdueDetailMapper  overdueDetailMapper;
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private OrderLogService orderLogService;
	@Autowired
	private DictService dictService;
	@Autowired
	private RepayDetailMapper repayDetailMapper;
	@Autowired
	private  TaskFlagMapper taskFlagMapper;
	@Autowired
	private LoanOrderMapper loanOrderMapper;
	@Autowired
	private  PayForService payForService;
	
	@Value("${spring.profiles.active}")
	private String active;
	
	
	@Autowired
	public RepayOrderService(CrudMapper<RepayOrder> mapper) {
		super(mapper);
	}

	/**
	 * @Description:贷后管理-还款订单列表
	 * @author likun
	 * @Create Time: 2017年10月31日上午10:35:43
	 */
	public Page<RepayOrder> pageRepayOrder(RepayOrder entity) {
		entity.setIsOverdue(0);// 未逾期
		long count = repayOrderMapper.getRepayOrderCount(entity);
		Page<RepayOrder> page = new Page<RepayOrder>(entity.getPageIndex_(), entity.getPageSize_());
		page.setData(repayOrderMapper.getRepayOrderList(entity));
		page.setTotalCount(count);
		return page;
	}

	/**
	 * @Description:贷后管理-逾期订单列表
	 * @author likun
	 * @Create Time: 2017年10月31日上午10:35:43
	 */
	public Page<RepayOrder> pageOverdueOrder(RepayOrder entity) {
		entity.setIsOverdue(1);// 逾期
		long count = repayOrderMapper.getRepayOrderCount(entity);
		Page<RepayOrder> page = new Page<RepayOrder>(entity.getPageIndex_(), entity.getPageSize_());
		page.setData(repayOrderMapper.getRepayOrderList(entity));
		page.setTotalCount(count);
		
		 buildOverdue( );
		return page;
	}
	/**
	 * @Description:我的未结清列表
	 * @author likun
	 * @Create Time: 2017年10月31日上午10:35:43
	 */
	public  List<RepayOrder> getUnclearedOrderByClientId(Map<String, Object> params){
		List<RepayOrder> repayOrders=repayOrderMapper.getUnclearedOrderByClientId(params);
		
		return  repayOrders;
	}
	/**
	 * @Description:贷后管理——逾期利息
	 * @author likun
	 * @Create Time: 2017年10月31日上午10:35:43
	 */
	public int buildOverdue( ) {
		//还款列表（未结清）
		RepayOrder entity=new RepayOrder();
		List<RepayOrder> repayOrders=repayOrderMapper.getUnclearedOrderList(entity);
		if (repayOrders.size() > 0) {
			LOGGER.info("===========================================当前未结清还款订单数量："+repayOrders.size()+"===========");
			for (int i = 0; i < repayOrders.size(); i++) {
				RepayOrder rOrder = repayOrders.get(i);
				OffsetDateTime exTime = rOrder.getExpirationTime();// 逾期时间
				OffsetDateTime nowTime = OffsetDateTime.now();// 当前时间
				Timestamp exTimeTamp=Timestamp.from(exTime.toInstant());
				Timestamp nowTimeTamp=Timestamp.from(nowTime.toInstant());
				LocalDate exTimeS=exTime.toLocalDate();
				LocalDate nowTimeS=nowTime.toLocalDate();
				if (nowTimeS.isAfter(exTimeS)  || nowTimeS.equals(exTimeS)) {//逾期了
					Map<String, Object> params = new HashMap<String, Object>();
					params.put("rOrderId", rOrder.getId());
					long overdueCount = repayOrderMapper.getTodayOverdueCount(params);
					LOGGER.info("===========================================当前逾期订单编号："+rOrder.getOrderNo()+"=========当天计息次数overdueCount："+overdueCount+"===========");
					if (overdueCount == 0) {
						/** 逾期天数、逾期等级、逾期金额、 */
						int overdueDays = DateTimeUtil.daysDifference( exTimeTamp ,nowTimeTamp);// 逾期天数
						overdueDays=overdueDays+1;
						int overdueGrade = getAbsTimeDiffMonth(exTime.toLocalDateTime(),nowTime.toLocalDateTime());// 逾期等级
						overdueGrade=overdueGrade+1;
						String overdueGradeStr = "M" + overdueGrade;
						LOGGER.info("===========================================逾期订单编号："+rOrder.getOrderNo()+"===逾期天数overdueDays："+overdueDays+"===逾期天数overdueGradeStr："+overdueGradeStr+"===========");
						BigDecimal repayAmount = rOrder.getRepayAmount();// 当前应还金额
						
//						BigDecimal flgAmount =rOrder.getLoanAmount();     //还款本金为借款金额
						BigDecimal flgAmount =new BigDecimal(1000);
						
						//罚息
						BigDecimal overdueAmount=new BigDecimal(0);
						// 新的应还金额
						BigDecimal newRepayAmount =new BigDecimal(0);
						
						if(repayAmount.compareTo(flgAmount) > 0 ||  repayAmount.compareTo(flgAmount) ==0){
							overdueAmount=overdueAmount.add(flgAmount.multiply(rOrder.getOverdueRate()).multiply(new BigDecimal(overdueDays)));
							newRepayAmount=newRepayAmount.add(flgAmount).add(overdueAmount);
						 }else {
							 overdueAmount = overdueAmount.add(repayAmount.multiply(rOrder.getOverdueRate()).multiply(new BigDecimal(overdueDays)));// 逾期金额
							 newRepayAmount=newRepayAmount.add(repayAmount).add(overdueAmount);
						}
						
						/** 记录逾期利息 */
						OverdueDetail oDetail = new OverdueDetail();
						oDetail.setRepayOrderId(rOrder.getId());
						oDetail.setRepayAmount(repayAmount);
						oDetail.setOverdueAmount(overdueAmount);
						oDetail.setOverdueDays(overdueDays);
						oDetail.setOverdueGrade(overdueGradeStr);
						oDetail.setCreateTime(OffsetDateTime.now());
						overdueDetailMapper.insert(oDetail);
						/** 更新还款记录 */
						RepayOrder newRepayOrder = new RepayOrder();
						newRepayOrder.setId(rOrder.getId());
						newRepayOrder.setRepayAmount(newRepayAmount);
						newRepayOrder.setIsOverdue(1);// 逾期
						newRepayOrder.setOverdueDays(overdueDays);
						newRepayOrder.setOverdueAmount(overdueAmount);
						newRepayOrder.setOverdueGrade(overdueGradeStr);
						newRepayOrder.setUpdateTime(OffsetDateTime.now());
						repayOrderMapper.update(newRepayOrder);
					}
				}
			}
		}
		return 1;
	}
	 /** 
     * 计算两个时间LocalDateTime相差的月数，不考虑日期前后，返回结果>=0 
     * 
     * @param before 
     * @param after 
     * @return 
     */  
    public int getAbsTimeDiffMonth(LocalDateTime before, LocalDateTime after) {  
  
        return Math.abs(Period.between(before.toLocalDate(), after.toLocalDate()).getMonths());  
    }
    /**
     * @Description:贷后管理-还款订单列表-还款短信
     * @author likun
     * @Create Time: 2017年11月2日上午10:33:00
     */
	public int repaySendSMS(RepayOrder repayOrder,Long userId) {
		/**还款短信*/
		int returnInt = 0;
		RepayOrder repayOrderData=repayOrderMapper.getRepaySendSMSInfo(repayOrder.getId());
		Map<String, String> params = dictService.getSmsDataConfig(0);
		
		StringBuilder content=new StringBuilder();
		content=content.append(repayOrderData.getRealName())
				.append("##").append(repayOrderData.getOrderNo())
				.append("##").append(repayOrderData.getRepayAmount())
				.append("##").append(repayOrderData.getExpirationShow().toLocalDate());
				
		try {
			params.put("content",   URLEncoder.encode(content.toString(),"utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		params.put("mobile", repayOrderData.getPhone());
	    params.put("templateId", "2009");  
		//参数：0 表示该短信为接口短信
		returnInt = SmsCodeUtil.sendSmsCode(params);
		/**订单操作日志*/
		orderLogService.insertOrderLog(userId,repayOrder.getId(),2,"发送还款短信:"+content);
		return returnInt;
	}
	 /**
     * @Description:贷后管理-还款订单列表-还款备注
     * @author likun
     * @Create Time: 2017年11月2日上午10:33:00
     */
	public int repayrRemark(RepayOrder repayOrder, Long userId) {
		/**更新还款订单备注*/
		RepayOrder newRepayOrder=new RepayOrder();
		newRepayOrder.setId(repayOrder.getId());
		newRepayOrder.setRemark(repayOrder.getRemark());
		repayOrderMapper.update(newRepayOrder);
		/**订单操作日志*/
		orderLogService.insertOrderLog(userId,repayOrder.getId(),2,"添加还款备注:"+repayOrder.getRemark());
		return 1;
	}
	 /**
     * @Description:贷后管理-还款订单列表-查看详情
     * @author likun
     * @Create Time: 2017年11月2日上午10:33:00
     */
	public RepayOrder getRepayOrderDetail(RepayOrder repayOrder) {
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("id",repayOrder.getId());
		RepayOrder  repayOrder2=repayOrderMapper.getRepayOrderDetail(params);	
	       
	    repayOrder2.setExpirationTime(repayOrder2.getExpirationShow());
		
		
		return repayOrder2;
	}  
	
	/**
	 * @Description:我的还款记录
	 * @author likun
	 * @Create Time: 2017年10月31日上午10:35:43
	 */
	public Page<RepayOrder> pageMyRepayOrder(RepayOrder entity) {
		long count = repayOrderMapper.getMyRepayOrdeCount(entity);
		Page<RepayOrder> page = new Page<RepayOrder>(entity.getPageIndex_(), entity.getPageSize_());
		page.setData(repayOrderMapper.getMyRepayOrderList(entity));
		page.setTotalCount(count);
		return page;
	}
	
	/**
	 * @Description:记录交易记录(立即还款)
	 */
	 public  int  updateRepayDetailByRepayment(RepayOrder repayOrder){
		    /**生成还款流水记录*/
			RepayDetail  qRepayDetail=new RepayDetail();
			qRepayDetail.setOrderType(2);
			qRepayDetail.setTradeNumber(repayOrder.getTradeNumber());//移动端输入
			//当前交易记录信息——通过申请流水号
			RepayDetail  repayDetail=repayDetailMapper.getRepayDetailByTradeNum(qRepayDetail);
			Long  id=repayDetail.getId();
			
			RepayDetail newRepayDetail=new RepayDetail();
			newRepayDetail.setId(id);
			newRepayDetail.setAmount(repayOrder.getRepayAmount());//交易金额
			newRepayDetail.setRepayType(repayOrder.getRepayResult());//3成功，4失败
			newRepayDetail.setSerialNumber(repayOrder.getSerialNumber());//交易流水号
			newRepayDetail.setRequestBody(repayOrder.getRequest());//交易请求
			newRepayDetail.setResponseBody(repayOrder.getResponse());//交易响应
			newRepayDetail.setUpdateTime(OffsetDateTime.now());
			repayDetailMapper.update(newRepayDetail);  
			
			return 1;
	   }
	/**
	 * @Description:立即还款，支付回调（代扣支付回调）
	 * @author likun
	 * @Create Time: 2017年11月21日上午9:24:18
	 * @param repayOrder
	 * @return
	 */
	public int repaymentCallBack(RepayOrder repayOrder) {
		/**修改还款记录*/
		LOGGER.info("==========================r立即还款，支付回调（代扣支付回调）开始============================");
		updateRepayByRepayment(repayOrder);
		LOGGER.info("==========================立即还款，支付回调（代扣支付回调）结束============================");
		return 1;
	}
	/**
	 * @Description:修改还款记录
	 */
	private  void updateRepayByRepayment(RepayOrder repayOrder ){
		LOGGER.info("==========================立即还款，支付回调（代扣支付回调）=======修改还款记录=====================");
		BigDecimal thisRepayAmount=repayOrder.getActualAmount();//支付通道返回的
		//当前还款订单信息——通过申请流水号
		RepayOrder  repayOrderData=repayOrderMapper.getRepayOrderInfoByTradeNum(repayOrder);
		LOGGER.info("==========================repaymentCallBack=======repayOrderData"+repayOrderData);
		BigDecimal  oldRepayAmount=repayOrderData.getRepayAmount();//当前应还
		BigDecimal oldActualRepayment=repayOrderData.getActualRepayment();//已经还款
		
		RepayOrder  newRepayOrder=new RepayOrder();
		if(thisRepayAmount.compareTo(oldRepayAmount) == 0 || thisRepayAmount.compareTo(oldRepayAmount) ==1){
			newRepayOrder.setStatus(2);//已结清
		}else{
			newRepayOrder.setStatus(1);//还款中
		}
		BigDecimal newRepayAmount=oldRepayAmount.subtract(thisRepayAmount);
		BigDecimal newActualRepayment=oldActualRepayment.add(thisRepayAmount);
		newRepayOrder.setRepayAmount(newRepayAmount);
		newRepayOrder.setActualRepayment(newActualRepayment);
		newRepayOrder.setId(repayOrderData.getId());
		newRepayOrder.setUpdateTime(OffsetDateTime.now());
		repayOrderMapper.update(newRepayOrder);
	}
    /**
     * @Description:定时代扣
     * @author likun
     * @Create Time: 2017年11月16日上午10:24:39
     * @return
     */
	public int withhold() {
		TaskFlag  taskFlag=new TaskFlag();
		taskFlag.setTaskType(2);//代扣
		long count =taskFlagMapper.getTodayCountByType(taskFlag);
		if(count ==0){
			//代扣订单—未结清且未逾期还款订单（逾期时间前一天）
			List<RepayOrder> rOrders=repayOrderMapper.getNotOverdueOrderList();
			LOGGER.info("======================未结清且未逾期还款订单:"+rOrders+"==================");
			if (rOrders.size() > 0) {
				LOGGER.info("=====================当前未结清还款订单数量："+rOrders.size()+"===========");
				for (int i = 0; i < rOrders.size(); i++) {
					try {
						/**自动还款扣款授权*/
						RepayOrder  repayOrder=new RepayOrder();
						long clientId=rOrders.get(i).getClientId();//会员主键
						BigDecimal  actualRepayAmount=rOrders.get(i).getRepayAmount();//（实际还款）
						String  orderNo=rOrders.get(i).getOrderNo();//订单编号
						
						repayOrder.setClientId(clientId);
					    repayOrder.setActualRepayment(actualRepayAmount);
					    repayOrder.setOrderNo(orderNo);
						 /**生成交易记录(代扣)+发起申请*/
					    String  tradeNum="7"+OrderNoUtil.getSerialNumber();//申请交易流水号
					    repayOrder.setTradeNumber(tradeNum);
					    /**生成交易记录(代扣)*/
					    createRepayDetailByWithhold(repayOrder);
					    
					    LOGGER.info("===============代扣=自动还款扣款授权==开始===============");
						Map<String, Object> applyResult =payForService.handleAuthorizationApplyFor(repayOrder);
						  /**更新——交易记录信息*/
						RepayOrder orderRecord =new RepayOrder();
					    orderRecord.setOrderNo(orderNo);
					    orderRecord.setActualRepayment(actualRepayAmount);//（实际还款）
					    orderRecord.setTradeNumber(tradeNum);////申请交易流水号
						/**银行卡还款扣款接口*/
						if("3000".equals(applyResult.get("resultCode"))){
							LOGGER.info("==扣款授权成功=========代扣=银行卡还款扣款接口==开始=============");
						    Map<String, Object> applyHandle = payForService.handleRepayment(repayOrder, applyResult.get("repaymentNo").toString());
						    String  code=(String) applyHandle.get("resultCode");
						    /**扣款——生成交易记录*/
						    orderRecord.setRequest(applyHandle.get("request").toString());//扣款请求参数
						    orderRecord.setResponse(applyHandle.get("response").toString());//扣款响应参数
						    
						    if("3000".equals(code)){
						    	orderRecord.setSerialNumber(applyHandle.get("serialNumber").toString());
						    	orderRecord.setRepayResult(5);//代扣成功
						    }else{
						    	orderRecord.setRepayResult(6);//代扣失败
						    }
						    updateRepayDetailByWithhold(orderRecord);
						    LOGGER.info("==扣款授权成功=========代扣=银行卡还款扣款接口==结束=============");
						}else{
							LOGGER.info("===============代扣=自动还款扣款授权==失败===============");
							 /**授权扣款——生成交易记录*/
							orderRecord.setRequest(applyResult.get("request").toString());//授权请求参数
							orderRecord.setResponse(applyResult.get("response").toString());//授权响应参数
							orderRecord.setRepayResult(6);//代扣失败
							
							updateRepayDetailByWithhold(orderRecord);
						}
						
					} catch (Exception e) {
						
						
						e.printStackTrace();
						
					}
				  }
				}
			
			taskFlag.setTaskName("withhold");
			taskFlag.setCreateTime(OffsetDateTime.now());
			taskFlagMapper.insert(taskFlag);
		}else{
			LOGGER.info("==============今日代扣已经执行==============");
		}
		return 1;
	}
	/**
	 * @Description:更新交易记录
	 * @author likun
	 * @Create Time: 2017年11月24日上午9:22:37
	 * @param orderRecord
	 */
	private void updateRepayDetailByWithhold(RepayOrder repayOrder) {
		 //当前交易记录信息
		RepayDetail  qRepayDetail=new RepayDetail();
		qRepayDetail.setOrderType(2);
		qRepayDetail.setTradeNumber(repayOrder.getTradeNumber());
		RepayDetail  repayDetail=repayDetailMapper.getRepayDetailByTradeNum(qRepayDetail);
		Long  id=repayDetail.getId();
		/***/
		RepayDetail newRepayDetail=new RepayDetail();
		newRepayDetail.setId(id);
		newRepayDetail.setRepayType(repayOrder.getRepayResult());//5代扣成功，6代扣失败
		newRepayDetail.setSerialNumber(repayOrder.getSerialNumber());//交易流水号
		newRepayDetail.setRequestBody(repayOrder.getRequest());//交易请求
		newRepayDetail.setResponseBody(repayOrder.getResponse());//交易响应
		newRepayDetail.setUpdateTime(OffsetDateTime.now());
		repayDetailMapper.update(newRepayDetail);  
		
	}

	/**
	 * @Description:生成交易记录(代扣)+发起申请
	 */
	public  int    createRepayDetailByWithhold(RepayOrder repayOrder){
		//当前还款订单信息——通过订单号
		RepayOrder repayOrderData= repayOrderMapper.getRepayOrderInfo(repayOrder);
		long  orderId=repayOrderData.getId();
		/***/
		RepayDetail repayDetail=new RepayDetail();
		repayDetail.setOrderId(orderId);
		repayDetail.setOrderType(2);//还款订单
		repayDetail.setTradeNumber(repayOrder.getTradeNumber());//申请交易流水号
		repayDetail.setAmount(repayOrder.getActualRepayment());//交易金额（实际还款）
		
		/**当前银行卡信息——通过订单号*/
		LoanOrder  loanOrder=new LoanOrder();
		loanOrder.setOrderNo(repayOrder.getOrderNo());
		LoanOrder  loanOrderData  =loanOrderMapper.getLoanOrderInfo(loanOrder);
		repayDetail.setBank(loanOrderData.getBank());
		repayDetail.setCardNo(loanOrderData.getCardNo());
		repayDetail.setCreateTime(OffsetDateTime.now());
		repayDetail.setRemark("自动代扣");
		repayDetailMapper.insert(repayDetail);  
		return 1;
	}
	
	/**
	 * @Description:记录交易记录(代扣)
	 */
	 public  int  insertRepayDetailByWithhold(RepayOrder repayOrder){
		   /**生成还款流水记录*/
		   //当前还款订单信息
			RepayOrder repayOrderData= repayOrderMapper.getRepayOrderInfo(repayOrder);
			long  orderId=repayOrderData.getId();
			/***/
			RepayDetail repayDetail=new RepayDetail();
			repayDetail.setOrderId(orderId);
			repayDetail.setOrderType(2);//还款订单
			
			repayDetail.setAmount(repayOrder.getActualRepayment());//交易金额（实际还款）
			repayDetail.setRepayType(repayOrder.getRepayResult());//5代扣成功，6代扣失败
			repayDetail.setSerialNumber(repayOrder.getSerialNumber());//交易流水号
			repayDetail.setRequestBody(repayOrder.getRequest());//交易请求
			repayDetail.setResponseBody(repayOrder.getResponse());//交易响应
			/**当前银行卡信息*/
			LoanOrder  loanOrder=new LoanOrder();
			loanOrder.setOrderNo(repayOrder.getOrderNo());
			LoanOrder  loanOrderData  =loanOrderMapper.getLoanOrderInfo(loanOrder);
			repayDetail.setBank(loanOrderData.getBank());
			repayDetail.setCardNo(loanOrderData.getCardNo());
			repayDetail.setCreateTime(OffsetDateTime.now());
			repayDetail.setRemark("自动代扣");
			repayDetailMapper.insert(repayDetail);  
			
			return 1;
	 }
	 
	    /**
		 * @Description:生成交易记录(立即)+发起申请
		 */
		public  String    createRepayDetailByRepayment(RepayOrder repayOrder){
			
			//当前还款订单信息——通过订单号
			RepayOrder repayOrderData= repayOrderMapper.getRepayOrderInfo(repayOrder);
			long  orderId=repayOrderData.getId();
			 /**生成交易记录(代扣)+发起申请*/
		    String  tradeNum="7"+OrderNoUtil.getSerialNumber();//申请交易流水号
		    
			/**交易记录信息*/
			RepayDetail repayDetail=new RepayDetail();
			repayDetail.setOrderId(orderId);
			repayDetail.setOrderType(2);//还款订单
			repayDetail.setTradeNumber(tradeNum);//申请交易流水号
			/**当前银行卡信息——通过订单号*/
			LoanOrder  loanOrder=new LoanOrder();
			loanOrder.setOrderNo(repayOrder.getOrderNo());
			LoanOrder  loanOrderData  =loanOrderMapper.getLoanOrderInfo(loanOrder);
			repayDetail.setBank(loanOrderData.getBank());
			repayDetail.setCardNo(loanOrderData.getCardNo());
			repayDetail.setCreateTime(OffsetDateTime.now());
			repayDetail.setRemark("立即还款");
			repayDetailMapper.insert(repayDetail);  
			return tradeNum;
		}
		
	 
}
